package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserFuBenZhanDou;

public class FuBenAdapter extends BaseAdapter {
    private Context context;
    private List<UserFuBenZhanDou> list;

    public List<UserFuBenZhanDou> getList() {
        return list;
    }

    public FuBenAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<UserFuBenZhanDou> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list==null){
            return 0;
        }else {
            return list.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.listview_nongyuan, null);
        ViewHolder viewHolder=new ViewHolder(view);
        String xinxi="";
        Log.v("12311123132111","21321321");
       if (list.get(i).getStw().equals("OK")){
           xinxi+="【胜利】获得经验："+list.get(i).getJy()+",金币："+list.get(i).getMoney();
           if (list.get(i).getShihun()!=0){
               xinxi+=",石魂*"+list.get(i).getShihun();
           }
           if (!list.get(i).getZhuangbei().trim().equals("")){
               xinxi+=","+list.get(i).getZhuangbei();
           }
           if (list.get(i).getSuipian()!=0){
               xinxi+=",技能残页:"+list.get(i).getSuipian();
           }
       }else if (list.get(i).getStw().equals("No1")){
           xinxi="【失败】敌人太强大了，你毫无还手之力。";
       }else if (list.get(i).getStw().equals("No2")){
           xinxi="【失败】即便是坚持了三十回合，但终究还是挂了。";
       }
       viewHolder.tvWp.setText(xinxi);
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvWp;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvWp = (TextView) rootView.findViewById(R.id.tvWp);
        }

    }
}
